exports.install = function (Vue) {
    // 获取token值
    Vue.prototype.getToken = function () {
        let currentUrl = window.location.href;
        let currentToken = currentUrl.split("&");
        localStorage.setItem("token", currentToken[1]);
    };
    // 获取数据字典
    Vue.prototype.getDictionary = function (el, el1) {
        let el1Arr = localStorage.getItem(el);
        el1Arr = el1Arr.split(",");
        let el1Obj = {};
        for (let i = 0; i < el1Arr.length; i++) {
            el1Obj["value"] = el1Arr[i];
            el1.push(el1Obj);
            el1Obj = {};
        }
        return el1;
    };
    // 图片上传
    Vue.prototype.uploadPic = function (el, el1, el2) {
        let formData = new FormData();
        formData.append('source', el.raw)
        this.$axios({
            method: "post",
            url: "/api/uploads/uploads",
            data: formData
        })
            .then(res => {
                if (res.data.status) {
                    this.$set(el1, el2, res.data.url);
                    return el1;
                } else {
                    this.$message.error(res.data.reason);
                }
            })
        if (el.raw.type != "image/png" && el.raw.type != "image/jpeg") {
            this.$message.error("图片只接收JPG或PNG格式!");
            return;
        }
        if (el.raw.size / 1024 / 1024 > 5) {
            this.$message.error("图片过大请稍后");
            return;
        }
    };
    //获取当前时间(年-月-日) n传入0即可获取当前时间 n传入30可获取前30天时间 向后 以此类推 
    Vue.prototype.getDate = function (n) {
        var n = n;
        var d = new Date();
        var year = d.getFullYear();
        var mon = d.getMonth() + 1;
        var day = d.getDate();
        if (day <= n) {
            if (mon > 1) {
                mon = mon - 1;
            } else {
                year = year - 1;
                mon = 12;
            }
        }
        d.setDate(d.getDate() - n);
        year = d.getFullYear();
        mon = d.getMonth() + 1;
        day = d.getDate();
        let s =
            year +
            "-" +
            (mon < 10 ? "0" + mon : mon) +
            "-" +
            (day < 10 ? "0" + day : day);
        return s;
    }
};